<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Boost搜索引擎</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            color: #333;
            line-height: 1.6;
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
        }
        
        header {
            text-align: center;
            margin: 30px 0;
        }
        
        .logo {
            font-size: 3.5rem;
            font-weight: bold;
            color: #4285f4;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .logo i {
            margin-right: 15px;
            font-size: 2.8rem;
        }
        
        .tagline {
            color: #5f6368;
            font-size: 1.2rem;
            margin-bottom: 30px;
        }
        
        .search-container {
            background: white;
            border-radius: 24px;
            box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
            padding: 30px;
            margin-bottom: 30px;
        }
        
        .search-box {
            display: flex;
            margin-bottom: 20px;
        }
        
        #search-input {
            flex: 1;
            padding: 16px 24px;
            border: 2px solid #dfe1e5;
            border-radius: 24px 0 0 24px;
            font-size: 16px;
            outline: none;
            transition: border-color 0.3s;
        }
        
        #search-input:focus {
            border-color: #4285f4;
        }
        
        #search-btn {
            padding: 16px 30px;
            background: linear-gradient(to right, #4285f4, #34a853);
            color: white;
            border: none;
            border-radius: 0 24px 24px 0;
            cursor: pointer;
            font-size: 16px;
            font-weight: bold;
            transition: opacity 0.3s;
        }
        
        #search-btn:hover {
            opacity: 0.9;
        }
        
        .filter-options {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            margin-top: 15px;
        }
        
        .filter-option {
            display: flex;
            align-items: center;
            background: #f1f3f4;
            padding: 8px 15px;
            border-radius: 18px;
            font-size: 14px;
            cursor: pointer;
            transition: background 0.3s;
        }
        
        .filter-option:hover {
            background: #e8eaed;
        }
        
        .filter-option.active {
            background: #4285f4;
            color: white;
        }
        
        .results-info {
            margin: 20px 0;
            color: #5f6368;
            font-size: 14px;
        }
        
        .results-container {
            margin-top: 20px;
        }
        
        .result-item {
            background: white;
            padding: 25px;
            margin-bottom: 20px;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            transition: transform 0.3s, box-shadow 0.3s;
        }
        
        .result-item:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        
        .result-title {
            font-size: 20px;
            color: #1a0dab;
            margin-bottom: 10px;
            text-decoration: none;
            display: block;
            font-weight: 500;
        }
        
        .result-title:hover {
            text-decoration: underline;
        }
        
        .result-url {
            color: #006621;
            font-size: 15px;
            margin-bottom: 12px;
            display: flex;
            align-items: center;
        }
        
        .result-url i {
            margin-right: 8px;
            font-size: 14px;
        }
        
        .result-desc {
            color: #545454;
            font-size: 16px;
            line-height: 1.5;
            margin-bottom: 15px;
        }
        
        .result-meta {
            display: flex;
            align-items: center;
            color: #70757a;
            font-size: 14px;
        }
        
        .result-weight {
            background: #f1f3f4;
            padding: 4px 10px;
            border-radius: 12px;
            margin-right: 15px;
        }
        
        .no-results {
            text-align: center;
            padding: 50px;
            color: #70757a;
            background: white;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
        }
        
        .no-results i {
            font-size: 50px;
            margin-bottom: 20px;
            color: #dadce0;
        }
        
        .loading {
            text-align: center;
            padding: 40px;
            display: none;
        }
        
        .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #4285f4;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        footer {
            text-align: center;
            margin-top: 50px;
            padding: 30px;
            color: #70757a;
            font-size: 14px;
            border-top: 1px solid #dadce0;
        }
        
        @media (max-width: 768px) {
            .search-box {
                flex-direction: column;
            }
            
            #search-input {
                border-radius: 12px;
                margin-bottom: 15px;
            }
            
            #search-btn {
                border-radius: 12px;
                padding: 14px;
            }
            
            .logo {
                font-size: 2.5rem;
            }
            
            .logo i {
                font-size: 2.2rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <div class="logo">
                <i class="fas fa-search"></i>
                <span>Boost搜索</span>
            </div>
            <p class="tagline">高效、精准的Boost库文档搜索</p>
        </header>
        
        <div class="search-container">
            <div class="search-box">
                <input type="text" id="search-input" placeholder="请输入关键词..." autocomplete="off">
                <button id="search-btn">搜索</button>
            </div>
            
            <div class="filter-options">
                <div class="filter-option active">全部</div>
                <div class="filter-option">文档</div>
                <div class="filter-option">教程</div>
                <div class="filter-option">示例</div>
                <div class="filter-option">API</div>
            </div>
        </div>
        
        <div class="loading">
            <div class="spinner"></div>
            <p>正在搜索中，请稍候...</p>
        </div>
        
        <div class="results-info" id="results-info"></div>
        
        <div class="results-container" id="results-container">
            <div class="no-results" id="no-results">
                <i class="fas fa-search"></i>
                <p>请输入关键词进行搜索</p>
            </div>
        </div>
        
        <footer>
            <p>© 2023 Boost搜索引擎 | 基于C++后端实现 | 提供高质量的Boost库文档搜索服务</p>
        </footer>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const searchInput = document.getElementById('search-input');
            const searchBtn = document.getElementById('search-btn');
            const resultsContainer = document.getElementById('results-container');
            const noResults = document.getElementById('no-results');
            const loading = document.querySelector('.loading');
            const resultsInfo = document.getElementById('results-info');
            const filterOptions = document.querySelectorAll('.filter-option');
            
            // 监听搜索按钮点击事件
            searchBtn.addEventListener('click', performSearch);
            
            // 监听回车键事件
            searchInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    performSearch();
                }
            });
            
            // 过滤器点击事件
            filterOptions.forEach(option => {
                option.addEventListener('click', function() {
                    filterOptions.forEach(opt => opt.classList.remove('active'));
                    this.classList.add('active');
                    // 这里可以添加过滤逻辑
                });
            });
            
            function performSearch() {
                const query = searchInput.value.trim();
                
                if (query === '') {
                    noResults.innerHTML = '<i class="fas fa-exclamation-circle"></i><p>请输入关键词</p>';
                    noResults.style.display = 'block';
                    resultsContainer.innerHTML = '';
                    resultsInfo.textContent = '';
                    return;
                }
                
                // 显示加载中
                loading.style.display = 'block';
                noResults.style.display = 'none';
                resultsContainer.innerHTML = '';
                resultsInfo.textContent = '搜索中...';
                
                // 发送搜索请求
                fetch(`/s?word=${encodeURIComponent(query)}`)
                    .then(response => {
                        if (!response.ok) {
                            throw new Error('网络响应不正常');
                        }
                        return response.json();
                    })
                    .then(data => {
                        // 隐藏加载中
                        loading.style.display = 'none';
                        
                        // 处理搜索结果
                        if (data && data.length > 0) {
                            displayResults(data, query);
                        } else {
                            noResults.innerHTML = '<i class="fas fa-search"></i><p>没有找到相关结果</p>';
                            noResults.style.display = 'block';
                            resultsInfo.textContent = `搜索 "${query}" 没有找到结果`;
                        }
                    })
                    .catch(error => {
                        loading.style.display = 'none';
                        noResults.innerHTML = `<i class="fas fa-exclamation-triangle"></i><p>搜索出错: ${error.message}</p>`;
                        noResults.style.display = 'block';
                        resultsInfo.textContent = '';
                        console.error('搜索错误:', error);
                    });
            }
            
            function displayResults(results, query) {
                resultsInfo.textContent = `找到 ${results.length} 条关于 "${query}" 的结果`;
                resultsContainer.innerHTML = '';
                
                results.forEach(result => {
                    const resultElement = document.createElement('div');
                    resultElement.className = 'result-item';
                    
                    resultElement.innerHTML = `
                        <a href="${result.url}" class="result-title">${result.title}</a>
                        <div class="result-url">
                            <i class="fas fa-link"></i>
                            ${result.url}
                        </div>
                        <div class="result-desc">${result.desc}</div>
                        <div class="result-meta">
                            <span class="result-weight">相关性: ${result.weight}</span>
                            <span>Boost库文档</span>
                        </div>
                    `;
                    
                    resultsContainer.appendChild(resultElement);
                });
            }
            
            // 初始示例数据（在没有后端时演示用）
            const exampleData = [
                {
                    "desc": "fails on sunos + oracle solaris studio compilers) thread safe library loading (fails on freebs",
                    "title": "Chapter 14. Boost.DLL",
                    "url": "./data/html/boost_dll.html",
                    "weight": 1
                },
                {
                    "desc": "Boost.Asio library for network and low-level I/O programming",
                    "title": "Chapter 5. Boost.Asio",
                    "url": "./data/html/boost_asio.html",
                    "weight": 2
                },
                {
                    "desc": "Boost.Filesystem provides facilities to manipulate files and directories",
                    "title": "Chapter 10. Boost.Filesystem",
                    "url": "./data/html/boost_filesystem.html",
                    "weight": 1
                }
            ];
            
            // 演示功能（实际使用时删除）
            searchInput.addEventListener('focus', function() {
                if (this.value === '') {
                    this.value = 'Boost.DLL';
                }
            });
            
            // 演示搜索功能
            setTimeout(() => {
                if (window.location.href.indexOf('demo=true') > -1) {
                    searchInput.value = 'Boost.DLL';
                    performSearch();
                }
            }, 500);
        });
    </script>
</body>
</html>